﻿using NJabber.Stream.Elements;

namespace NJabber.Client.StanzaFactories
{
    public class SubscriptionStanzaFactory : StanzaFactory<StanzaParameters>, ISubscriptionStanzaFactory
    {
        public Stanza CreateSubscribeRequest(JID receiverId)
        {
            return CreateSubscriptionStanza(PresenceStanzaType.Subscribe, receiverId);
        }

        public Stanza CreateSubscriptionApproveResponse(JID receiverId)
        {
            return CreateSubscriptionStanza(PresenceStanzaType.Subscribed, receiverId);
        }

        public Stanza CreateSubscriptionDenyResponse(JID receiverId)
        {
            return CreateSubscriptionStanza(PresenceStanzaType.Unsubscribed, receiverId);
        }

        public Stanza CreateSubscriptionCancellationRequest(JID receiverId)
        {
            return CreateSubscriptionStanza(PresenceStanzaType.Unsubscribed, receiverId);
        }

        public Stanza CreateUnsubscribeRequest(JID receiverId)
        {
            return CreateSubscriptionStanza(PresenceStanzaType.Unsubscribe, receiverId); ;
        }

        private Stanza CreateSubscriptionStanza(string type, JID receiverId)
        {
            PresenceStanza stanza = CreateStanza<PresenceStanza>();
            stanza.Type = type;
            stanza.To = receiverId;
            return stanza;
        }
    }
}
